package com.bang.concurrency.example.syncContainer;

import com.bang.concurrency.annotations.ThreadSafe;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.Vector;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;

/**
 * @Auther: Bang
 * @Date: 2019/10/1 00:11
 * @Description:
 */
@Slf4j
public class VectorExample2 {



    private static List<Integer> list = new Vector<>();

    public static void main(String[] args) throws InterruptedException {
        ExecutorService executorService = Executors.newCachedThreadPool();
        int count = 0;
        while (true) {
            count++;
            if (count > 1000) {
                break;
            }
            for (int i = 0; i < 10; i++) {
                list.add(i);
            }
            executorService.execute(()->{
                for (int i = 0; i < list.size(); i++) {
                    list.remove(i);
                }
            });

            executorService.execute(()->{
                for (int i = 0; i < list.size(); i++) {
                    list.get(i);
                }
            });

        }

    }

}
